<template>
	<view>
		<view class="user-card">
			<view class="item title">
				<view class="left">
					提现账户
				</view>
				<view class="right">
					仅限提现到当前微信账户
				</view>
			</view>
			<view class="item">
				<view class="user-info">
					<image :src="userInfo.icon" mode=""></image>
					<text>{{userInfo.name}}</text>
				</view>
			</view>
		</view>
		<view class="user-name">
			<view class="title">
				请输入真实姓名
			</view>
			<view class="input">
				<input type="text" v-model="name" placeholder="请输入您的真实姓名" >
			</view>
		</view>
		<view class="info-card">
			<view class="title">
				提现金额
			</view>
			<view class="money">
				<text class="money-text">￥</text>
				<input type="digit" v-model="value" maxlength="3">
				<!-- <text class="btn-text">全部提现</text> -->
			</view>
			<view class="abstract">
				最大可提现金额：100  I  满0.3元 可提现
			</view>
			<view class="btn" @tap="handleWithdraw">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value:'',
				userInfo:{},
				name:'',
				click:true
			};
		},
		onLoad() {
			this.getUserInfo()
		},
		methods:{
			debounce(fn, delay) {
				
				var time = null;//time用来控制事件的触发
				return function(){
					if (time !== null) {
						clearTimeout(time);
					}
					time = setTimeout(() => {
						console.log(111);
						
						fn()
						//利用call(),让this的指针从指向window 转成指向input
					}, delay)
				}
			},
			async handleWithdraw(){
				var that = this
				
				if(!this.name){
					uni.showToast({
						icon:"none",
						title:'请输入姓名',
					})
					return
				}
				if(!this.value){
					uni.showToast({
						icon:"none",
						title:'请输入金额',
					})
					return
				}
				if(this.value < 0.3){
					uni.showToast({
						icon:"none",
						title:'请至少输入大于0.3的金额',
					})
					return
				}
				const data = {
					uid: uni.getStorageSync('uid'),
					money: this.value,
					name: this.name
				};
				if(that.click){
					that.click = false
					setTimeout(()=>{
						that.click = true
					},5000)
					var res = await this.$request('user/withdraw',data,{ showLoading: true })
					console.log(res);
					if (res.result == 0) {
						uni.showToast({
							icon:"none",
							title:res.resultNote,
							mask:true
						})
						setTimeout(()=>{
							uni.switchTab({
								url:"/pages/tabs/me"
							})
						},1500)
					} else {
						uni.showToast({
							icon:"none",
							title:res.resultNote,
						})
					}
				}
				
			}
		},
		watch:{
			value(e){
			    if(e > 100){
					this.value=100
			    }
			}
		}
	}
</script>

<style lang="scss" scoped> 
	.user-card{
		background-color: #fff;
		padding: 0 40rpx;
		height: 222rpx;
		.item{
			
			.left{
				
				font-size: 28rpx;
				font-weight: 500;
				color: #000000;
			}
			.right{
				font-size: 24rpx;
				font-weight: 500;
				color: #999999;
			}
			.user-info{
				height: 126rpx;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				image{
					width: 60rpx;
					height: 60rpx;
					border-radius: 50%;
					margin-right: 22rpx;
				}
				text{
					font-size: 24rpx;
					font-weight: 500;
					color: #333333;
				}
			}
		}
		.title{
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 95rpx;
			border-bottom: 2rpx solid rgba(231, 231, 231, .5);
		}
	}
	.user-name{
		height: 200rpx;
		background-color: #fff;
		padding: 0 40rpx;
		margin-top: 20rpx;
		overflow: hidden;
		.title{
			font-size: 28rpx;
			font-weight: 500;
			color: #000000;
			line-height: 36rpx;
			margin: 38rpx 0 25rpx;
		}
		.input{
			width: 450rpx;
			font-size: 38rpx;
			font-weight: bold;
			color: #999999;
			line-height: 36rpx;
		}
	}
	.info-card{
		height: 572rpx;
		background-color: #FFFFFF;
		margin-top: 20rpx;
		padding: 0 40rpx;
		overflow: hidden;
		.title{
			font-size: 28rpx;
			font-weight: 500;
			color: #000000;
			line-height: 36rpx;
			margin: 38rpx 0 25rpx;
		}
		.money{
			width: 670rpx;
			height: 81rpx;
			background: #F7F9FB;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			margin-bottom: 25rpx;
			padding: 0 20rpx;
			.money-text{
				font-size: 30rpx;
				font-weight: bold;
				color: #FF0000;
				line-height: 36rpx;
			}
			input{
				width: 450rpx;
				font-size: 38rpx;
				font-weight: bold;
				color: #FF0000;
				line-height: 36rpx;
			}
			.btn-text{
				font-size: 24rpx;
				font-weight: 500;
				color: #246697;
				line-height: 36rpx;
			}
		}
		.abstract{
			font-size: 24rpx;
			font-weight: 500;
			color: #666666;
			line-height: 36rpx;
			margin-bottom: 107rpx;
		}
		.btn{
			width: 670rpx;
			height: 100rpx;
			margin-top: 150rpx;
			background: $uni-color-bg;
			border-radius: 50rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 100rpx;
			text-align: center;
		}
	}
</style>
